package com.ocm.commerceinteraction.ui;

import android.app.Activity;
import android.graphics.Color;
import android.os.Build;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;

import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.ocm.commerceinteraction.model.BaseModel;
import com.readystatesoftware.systembartint.SystemBarTintManager;

/**
 * Created by Curry on 2016-4-30.
 */
public abstract class BaseActivity extends Activity {
    //    protected ObjectMapper objectMapper = new ObjectMapper();
    Gson gson = new Gson();

    abstract void initView();

    abstract void Click(View view);

    //    XTHttp xtHttp = new XTHttp();
    String param;

    protected String requestUrl = "";//访问地址
    protected String requestParams = "";//访问参数
    protected BaseModel baseModel;

    /**
     * 处理返回基本结构信息数据
     *
     * @param object 返回json结构
     */
    protected void dealBaseData(Object object) {
        try {
            baseModel = gson.fromJson(object.toString(), BaseModel.class);
        } catch (JsonSyntaxException e) {
            baseModel = gson.fromJson(object.toString(), BaseModel.class);
        }
        Toast.makeText(this, baseModel.getMsg(), Toast.LENGTH_SHORT).show();
    }

    /**
     * 设置状态栏背景状态
     */
    protected void setTranslucentStatus() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            Window win = getWindow();
            WindowManager.LayoutParams winParams = win.getAttributes();
            final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
            winParams.flags |= bits;
            win.setAttributes(winParams);
        }

        SystemBarTintManager tintManager = new SystemBarTintManager(this);
        // enable status bar tint
        tintManager.setStatusBarTintEnabled(true);
        // enable navigation bar tint
        tintManager.setNavigationBarTintEnabled(true);
        // set a custom tint color for all system bars
        tintManager.setTintColor(Color.parseColor("#2ed5bc"));
    }
}
